﻿using FairyGUI;
public class UI_Register : Window
{
    public GButton m_btnCancel;
    public GButton m_btnConfirm;
    public GTextInput m_inputUser;
    public GTextInput m_inputPassWd;

    protected override void OnInit()
    {
        base.OnInit();
        this.contentPane = UIManager.Instance.LoadComponent("Login", "UIRegister");
        m_btnCancel = (GButton)this.contentPane.GetChild("btnCancel");
        m_btnConfirm = (GButton)this.contentPane.GetChild("btnConfirm");
        m_inputUser = (GTextInput)this.contentPane.GetChild("inputUser");
        m_inputPassWd = (GTextInput)this.contentPane.GetChild("inputPassWd");

        //取消
        m_btnCancel.onClick.Add(() =>
        {
            this.Hide();
            UIManager.Instance.ShowWindow<UI_Login>();
        });
        //确定
        m_btnConfirm.onClick.Add(() =>
        {
            string user = m_inputUser.text;
            string passwd = m_inputPassWd.text;
            if (user.Length == 0)
            {
                UI_Message panel = UIManager.Instance.ShowWindow<UI_Message>();
                panel.Message("请输入账号!");
                return;
            }
            if (passwd.Length == 0) {
                UI_Message panel = UIManager.Instance.ShowWindow<UI_Message>();
                panel.Message("请输入密码!");
                return;
            }
            if (!AccountMgr.Instance.Register(user, passwd))
            {
                UI_Message panel = UIManager.Instance.ShowWindow<UI_Message>();
                panel.Message("账号已注册,请更换账号!");
                return;
            }
            UI_Message tipSuccess = UIManager.Instance.ShowWindow<UI_Message>();
            tipSuccess.Message("注册成功!", ()=>
            {
                 this.Hide();
                UIManager.Instance.ShowWindow<UI_Login>();
            });
        });
    }
}